package com.example.tool.action.util;

import com.example.tool.action.ActionUtil;
import com.example.tool.utils.FileUtil;
import com.intellij.openapi.actionSystem.ActionUpdateThread;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.vfs.VirtualFileManager;
import org.jetbrains.annotations.NotNull;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * <p>Title: DateUtilActions</p>
 * Description: 创建时间日期工具类
 * <p>CreateTime: 2022/9/8 14:43</p>
 * @author FT
 */
public class DateUtilActions extends AnAction {

  @Override
  public @NotNull ActionUpdateThread getActionUpdateThread() {
    return super.getActionUpdateThread();
  }

  @Override
  public void actionPerformed(@NotNull AnActionEvent e) {
    ActionUtil.ActionCreatInput(e, (information, value) -> {
      String className = value.get(0);
      // xx.java
      FileUtil.generateFile(information[0] + "/" + className + ".java", "/demo/init/utils/DateUtil.txt",
          str -> str.replace("$package$", information[1])
              .replace("$ClassName$", className)
              .replace("$TIME$", new SimpleDateFormat("yyyy-MM-dd").format(new Date())));
      VirtualFileManager.getInstance().refreshWithoutFileWatcher(false);
    }, "日期工具类名: ");
  }

  @Override
  public void update(@NotNull AnActionEvent event) {
    ActionUtil.ActionP(event);
  }
}